package com.nbjtjc.safe.api.sys;

import com.nbjtjc.safe.api.AbstractController;
import com.nbjtjc.safe.bean.Page;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.sys.SysUserRole;
import com.nbjtjc.safe.service.sys.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户角色
 */
@RequestMapping("/userRole")
@RestController
//@CrossOrigin(allowCredentials = "true",origins = {"http://localhost:8083","http://192.168.20.4:8083","http://192.168.20.4:8899","http://192.168.20.42:8899"})
@CrossOrigin(allowCredentials = "true",origins = {"*"})
public class SysUserRoleController extends AbstractController<SysUserRole> {


    @Autowired
    private SysUserRoleService sysUserRoleService;
    @RequestMapping(value = "/add",method = {RequestMethod.POST})
    public Result addUserRole(int[] roleIds, int userId){
        Result userRoleResult=new Result<>();
        try {
            userRoleResult=sysUserRoleService.add(roleIds,userId);
        } catch (Exception e) {
            e.printStackTrace();
            userRoleResult.setFalse(e.getMessage());
        }
        return userRoleResult;
    }

    @RequestMapping(value = "/delete",method = {RequestMethod.POST})
    public Result<Boolean> delete(int userRoleId){
        Result<Boolean> result=new Result<>();
        try {
            sysUserRoleService.delete(userRoleId);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }

    @Override
    public Result find(SysUserRole param, Page page) {
        return null;
    }
}
